<?php
/**
* @version              $Id: view.html.php 9764 2007-12-30 07:48:11Z ircmaxell $
* @package              Joomla
* @subpackage   Poll
* @copyright    Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
* @license              GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die();

jimport( 'joomla.application.component.view');

class amapViewliste_personnes_relai extends JView {

var $amap;

        function display($tpl = null)
        {
   $mainframe =& JFactory::getApplication();

                $database =& JFactory::getDBO();
                $document =& JFactory::getDocument();
                $user =& JFactory::getUser();


$ida=$mainframe->getUserState('amap_ida');
$html='<div style="text-align:center;">AMAP®  Luy de Béarn</div>';

$norelai=1;
$i=0;

//le cas de 'tous' n'est pas traité


$relailiste=Array();
while ($norelai < 11)
{
$sql="SELECT amap_abonnement.Produit as produit,amap_adherent.Nom as nom,Prenom as premom,Adresse as adresse,CP as cp,Ville as ville,Fixe as fixe,Mobile as mobile,Email as mail  FROM `amap_adherent` JOIN amap_abonnement ON amap_abonnement.Nom=amap_adherent.relai$norelai WHERE relai$norelai<>'' order by amap_abonnement.Produit;";

//echo "$sql<br>";
$database->setQuery( $sql);
$relai=$database->loadRowList();
foreach ($relai as $ligne)  {
//echo $ligne['0'].'<br>'; 
$relailiste[$i][0]=$ligne['0'];//Produit
$relailiste[$i][1]=$ligne['1'];//Nom
$relailiste[$i][2]=$ligne['2'];//Prenom
$relailiste[$i][3]=$ligne['3'];//Adresse
$relailiste[$i][4]=$ligne['4'];//CP
$relailiste[$i][5]=$ligne['5'];//Ville
$relailiste[$i][6]=$ligne['6'];//Fixe
$relailiste[$i][7]=$ligne['7'];//Mobile
$relailiste[$i][8]=$ligne['8'];//Email
$i=$i+1;
}
$norelai=$norelai+1;

}
sort($relailiste);
//var_dump($relailiste);
$k=0;
$listeunique=Array();
$relailisteprec=Array();
while ($k<$i)
{
if($relailisteprec==$relailiste[$k][0] .' '. $relailiste[$k][1]." ".$relailiste[$k][2])
{

$listeunique[$k]['0']=$relailiste[$k]['0'];
$listeunique[$k]['1']=$relailiste[$k]['1'];
$listeunique[$k]['2']=$relailiste[$k]['2'];
$listeunique[$k]['3']=$relailiste[$k]['3'];
$listeunique[$k]['4']=$relailiste[$k]['4'];
$listeunique[$k]['5']=$relailiste[$k]['5'];
$listeunique[$k]['6']=$relailiste[$k]['6'];
$listeunique[$k]['7']=$relailiste[$k]['7'];
$listeunique[$k]['8']=$relailiste[$k]['8'];
}
$k=$k+1;
$relailisteprec=$relailiste[$k][0] .' '. $relailiste[$k][1]." ".$relailiste[$k][2];
}
$nb=$k;
$k=0;
//echo "nb $nb";
//var_dump($listeunique);

$html.='<strong><h2>Liste des personnes relai au '. date('d-m-Y').'</strong></h2><br>';

$html.='<TABLE border="1">';
while ($k<$nb)
{ 
if ($prec==$listeunique[$k]['0'].$listeunique[$k]['1'].$listeunique[$k]['2']) $k=$k+1;loop;

if ($prec===$listeunique[$k]['0'].$listeunique[$k]['1'].$listeunique[$k]['2'])$k=$k+1;loop;
$html.='<TR><TD>'.$listeunique[$k]['0'].'</TD><TD>'.$listeunique[$k]['1'].'</TD><TD>'.$listeunique[$k]['2'].'</TD><TD>'.$listeunique[$k]['3'].'</TD><TD>'.$listeunique[$k]['4'].'</TD><TD>'.$listeunique[$k]['5'].'</TD><TD>'.$listeunique[$k]['6'].'</TD><TD>'.$listeunique[$k]['7'].'</TD><TD width="20%">'.$listeunique[$k]['8'].'</TD></TR>';
$prec=$listeunique[$k]['0'].$listeunique[$k]['1'].$listeunique[$k]['2'];
$k=$k+1;

}

$html.='</TABLE>';
//echo $html;
$fichier="Liste des personnes relai";
contratPDF($html,$fichier);

}
}

?>
